<template>
  <div class="login">
    <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form">
      <div class="logo">
      <img class="logoimg" src="../assets/logo/logo.png"/>
      <h1 class="title">飘安生产管理系统</h1>
      </div>
      <div class="tit" style="text-align:center;display:flex;">
        <span style="color:#333;">............</span>
        <img src="../assets/logo/title.png" style="width:238px;height:24px;margin-bottom:18px;margin-left:7px;margin-right:7px;"/>
         <span style="color:#333;">..........</span>
      </div>
      <div class="english">
        <p class="text-tit">THE SOURCE CAN BECHECKEDAND ATIONCANBETRACED</p>
      </div>
      <el-form-item prop="username">
        <el-input
          v-model="loginForm.username"
          type="text"
          auto-complete="off"
          placeholder="账号"
        >
          <svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" />
        </el-input>
      </el-form-item>
      <el-form-item prop="password">
        <el-input
          v-model="loginForm.password"
          type="password"
          auto-complete="off"
          placeholder="密码"
          @keyup.enter.native="handleLogin"
          show-password
        >
          <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" />
        </el-input>
      </el-form-item>
      <div class="login-checked">
        <el-checkbox v-model="isPassword" class="login-password">记住密码</el-checkbox>
        <!-- <el-checkbox v-model="checked"></el-checkbox> -->
        <!-- <router-link class="login-checked-span" :to="'/agreement'">软件使用协议</router-link> -->
      </div>
      <el-form-item style="width:100%;">
        <el-button
          :loading="loading"
          size="medium"
          type="primary"
          style="width:100%;"
          @click.native.prevent="handleLogin"
          class="btn-sear"
          color="#28C6C6"
        >
          <span v-if="!loading">登 录</span>
          <span v-else>登 录 中...</span>
        </el-button>
        <div style="float: right;" v-if="register">
          <router-link class="link-type" :to="'/register'">立即注册</router-link>
        </div>
      </el-form-item>
    </el-form>
    <div class="copyright">© 2022 <a href="https://beian.miit.gov.cn" target="_blank">沪ICP备2022011102号</a></div>
  </div>
</template>

<script>
import Cookies from "js-cookie";
import { encrypt } from '@/utils/jsencrypt'

export default {
  name: "Login",
  data() {
    return {
      codeUrl: "",
      loginForm: {
        username: "",
        password: "",
        uuid: "",
      },
      loginRules: {
        username: [
          { required: true, trigger: "blur", message: "请输入您的账号" }
        ],
        password: [
          { required: true, trigger: "blur", message: "请输入您的密码" }
        ],
      },
      checked: false,
      loading: false,
      isPassword: true,
      // 验证码开关
      captchaOnOff: true,
      // 注册开关
      register: false,
      redirect: undefined
    };
  },
  watch: {
    $route: {
      handler: function(route) {
        this.redirect = route.query && route.query.redirect;
      },
      immediate: true
    }
  },
  created() {
    this.getCookie();
  },
  methods: {
    getCookie() {
      this.loginForm.username = Cookies.get("username")
      this.loginForm.password = Cookies.get("password")
      if(Cookies.get("isPassword") !== undefined){
        this.isPassword = Boolean(Cookies.get("isPassword"))
      }
    },
    handleLogin() {
      this.$refs.loginForm.validate(valid => {
        if (valid) {
          this.loading = true;
          if (this.isPassword == true) {
            Cookies.set("username", this.loginForm.username)
            Cookies.set("password", this.loginForm.password)
            Cookies.set("isPassword", this.isPassword)
          } else {
            Cookies.remove("username")
            Cookies.remove("password")
            Cookies.remove("isPassword")
          }
          // if(this.checked == false){
          //   this.loading = false
          //   this.$modal.msgError('请勾选软件使用协议！')
          // }else{
            this.$store.dispatch("Login", this.loginForm).then(() => {
              this.$router.push({ 
                // path: this.redirect || "/"
                path: "/"
              }).catch(()=>{});
            }).catch(() => {
              this.loading = false
            })
          // }
        }
      })
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss">
.login {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%;
  background-image: url("../assets/img/Login/login-bjimg.jpeg");
  background-size: cover;
}
.logo{
  display: flex;
  margin-bottom:20px;
}
.logoimg{
  width:48px;
  height: 48px;
}
.title {
 font-size: 34px;
font-family: Microsoft YaHei;
font-weight: bold;
color: #222222;
margin-left:10px;
}
.text-tit{
font-size: 9px;
font-family: Arial;
font-weight: 400;
color: #222222;
line-height: 28px;
margin-bottom:10px;
}
.login-form {
  border-radius: 6px;
  // background: rgba($color: #ffffff, $alpha: 0.4);
  width: 400px;
  padding: 25px 25px 5px 25px;
   margin-left:400px;
  .el-input {
    height: 38px;
    input {
      height: 38px;
    }
  }
  .input-icon {
    height: 39px;
    width: 14px;
    margin-left: 2px;
  }
}
.login-tip {
  font-size: 13px;
  text-align: center;
  color: #bfbfbf;
}
.login-code {
  width: 33%;
  height: 38px;
  float: right;
  img {
    cursor: pointer;
    vertical-align: middle;
  }
}
.el-login-footer {
  height: 40px;
  line-height: 40px;
  position: fixed;
  bottom: 0;
  width: 100%;
  text-align: center;
  color: #fff;
  font-family: Arial;
  font-size: 12px;
  letter-spacing: 1px;
}
.login-code-img {
  height: 38px;
}
.login-password .el-checkbox__label{
  color:#000!important;
}
.login-checked{
  display:flex;
  align-items: center;
  margin-bottom: 10px;
}
.login-checked .login-checked-span{
  padding-left: 10px;
  // color:#28C6C6;
  color:#000;
  font-size:14px;
  text-decoration: underline;
  cursor: pointer;
}
.copyright{
  position: absolute;
  bottom: 10px;
  color: #fff;
  font-size: 12px;
}
.copyright a{
  color:#fff;
  font-size: 12px;
}
</style>
